<?php
namespace Home\Controller;

class DownloadController extends HomeController{
		
	//系统首页
	public function download(){
		$film_name = trim(I('get.film_name'));
		$ch = curl_init();
		$url = "http://movie.douban.com/subject_search?search_text=".$film_name;
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, "Content-type:text/html;charset=utf-8");
		$res = curl_exec($ch);
		$pattern = '/<a class="nbg" href="http:\/\/movie.douban.com\/subject\/(.*)\/" onclick=(.*); title="(.*)">/iUs';
		preg_match($pattern, $res,$res1);
		curl_close($ch);
		
		$ch = curl_init();
		$url = "http://movie.douban.com/subject/".$res1[1]."/";
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, "Content-type:text/html;charset=utf-8");
		$res = curl_exec($ch);
		$pattern = '/<div id="info">(.*)<\/div>/iUs';
		$pattern1 = '/<div id="interest_sectl">(.*)<\/span>
                <br \/>
            
    <\/div>/iUs';
		$pattern2 = '/<img src="http:\/\/img3.douban.com\/view\/movie_poster_cover\/spst\/public\/p(.*).jpg" title="点击看更多海报" alt="Pan" rel="v:image" \/>/iUs';
		$pattern3 = '/<span property="v:summary" class="">(.*)<\/span>/iUs';
		$pattern4 = '/<div class="rating_betterthan">(.*)<\/div>/iUs';
		preg_match($pattern, $res,$res1);//影片详细信息
		preg_match($pattern1, $res,$res2);//影片评分
//		preg_match($pattern2, $res,$res3);//图片
		preg_match($pattern3, $res,$res4);
		preg_match($pattern4, $res,$res5);
		curl_close($ch);
		//echo $res1[0][0];
//		dump($res1);
//		dump($res2);
//		dump($res4);
//		dump($res5);
		$film_info = array();
		$film_info['film_detail'] = $res1[0];
		$film_info['film_score'] = $res2[0];
		$film_info['film_intro'] = $res4[0];
		$film_info['film_compare'] = $res5[0];
		//根据film_id从数据库中读取该部电影的封面链接和下载链接
		$film_id = I('get.id');
		D('FilmClick')->update_click_num($film_id);
		$res = D('FilmDownloadLink')->get_film_info($film_id);
		$film_info['film_download_link'] = $res;
		//dump($film_info);
		$this->assign('film_info',$film_info);
		$this->display();
	}
}	
?>